package com.zbkj.common.utils;

import com.baomidou.mybatisplus.extension.api.R;

import java.util.Random;

/**
 * @Auther:
 * @Date: 2024/9/11 22:07
 * @Description:
 */
public class RandomCodeUtil {

    public static String getRandomCode(int codeLength) {
        if(codeLength <0) {
            return null;
        }
        Random random = new Random();
        StringBuilder code = new StringBuilder();
        for(int i=0; i<codeLength; i++) {
            int cr = random.nextInt(3);
            switch (cr) {
                case 0:
                    code.append(random.nextInt(10));
                    break;
                case 1:
                    code.append((char) (random.nextInt(26) + 'a'));
                    break;
                case 2:
                    code.append((char) (random.nextInt(26) + 'A'));
                    break;
                default:
                    break;
            }
        }
        return code.toString();
    }
}
